<?php
/**
 * Created by IntelliJ IDEA.
 * User: kaireewu
 * Date: 11-9-28
 * Time: 上午11:12
 * To change this template use File | Settings | File Templates.
 */
$value = $str = $type = '';
$str = isset($_POST['str']) ? html_entity_decode($_POST['str']) : '';
$type = isset($_POST['type']) ? trim($_POST['type']) : '';
$value = empty($str) ? '' : md5($str);
if ($type != 'ajax') {
?>
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>在线加密</title>
</head>
<body>
<form method="POST">
    <fieldset>
        <legend>PHP加密</legend>
        <p><label for="str">要加密的文字：</label><input type="text" name="str" id="str" value="<?php echo $value;?>"></p>
        <p><input type="submit" value="提交"></p>
    </fieldset>
</form>
<form method="POST">
    <fieldset>
        <legend>时间票</legend>
        <p><label for="time">时间字符串：</label><input type="text" name="time" id="time" value="<?php echo $value;?>"></p>
        <p><input type="submit" value="提交"></p>
    </fieldset>
</form>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
//<!--
$("form").submit(function(event){
   var name = $("input:text", this).get(0).attr('name');
   var postData = "";
   if (name == 'str'){
       postData = "do=md5&str=" + $("#str").val() + "&type=ajax";
       $.post('query.php',
               postData,
               function(result, textStatus, jqXHR){
                   $("#str").val(result);
               },
               'text'
       );
   } else if(name = 'time') {
       postData = "do=mktime&time=" + $("#time").val() + "&type=ajax";
       $.post('query.php',
               postData,
               function(result, textStatus, jqXHR){
                   $("#time").val(result);
               },
               'text'
       );
   }
   event.preventDefault();
   return false;
});
//-->
</script>
</body>
</html>
<?php
} else {
    header('content-type:text/plain; charset=UTF-8');
    echo $value;
}
?>